using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using WebapiTemplate.Application.Common.Interface;

namespace WebapiTemplate.Infrastructure.Identity
{
    public class SessionUserService : ISessionUserService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;


        public SessionUserService(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }

        public Guid? UserId
        {
            get
            {
                var UserId = _httpContextAccessor.HttpContext?.User.FindFirstValue("UserId");
                if (UserId != null)
                {

                    return new Guid(UserId);
                }
                return null;
            }
        }

        public string? Username
        {
            get
            {
                var Username = _httpContextAccessor.HttpContext?.User.FindFirstValue("Username");

                return Username;
            }
        }
    }
}